package team.seekers.hula.course.resource.problem.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.PageResult;
import team.seekers.hula.auth.service.MindUtils;
import team.seekers.hula.course.resource.problem.entity.dto.ProblemDTO;
import team.seekers.hula.course.resource.problem.entity.dto.ProblemPageQueryDTO;
import team.seekers.hula.course.resource.problem.entity.vo.ProblemListVO;
import team.seekers.hula.course.resource.problem.entity.vo.ProblemPageListVO;
import team.seekers.hula.course.resource.problem.service.ProblemService;

import java.util.List;

/**
 * date: 2022/5/3 12:03
 *
 * @author GH
 * QQ 1124813753
 */
@Slf4j
@Controller
@ApiResponseBody
@RequestMapping("/manage/problem")
public class ProblemManageController {

    @Autowired
    private ProblemService problemService;

    @PostMapping("/saveOrUpdate")
    public String saveOrUpdate(@RequestBody ProblemDTO problemDTO) {
        problemDTO.setUserId(MindUtils.getUserId());
        return problemService.saveOrUpdate(problemDTO);
    }

    @GetMapping("/delete")
    public void delete(@RequestParam Long problemId) {
        problemService.delete(problemId, MindUtils.getUserId());
    }

    @GetMapping("/list")
    public List<ProblemListVO> list(@RequestParam(value = "description",required = false) String description) {
        return problemService.list(description);
    }

    @GetMapping("/page")
    public PageResult<ProblemPageListVO> page(ProblemPageQueryDTO dto) {
        return problemService.page(dto);
    }

    @GetMapping("/info")
    public ProblemDTO info(@RequestParam String problemId) {
        return problemService.info(problemId);
    }
}
